package ebj.common.java8.collection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

import org.apache.http.client.params.AllClientPNames;

public class BaseClass {
    protected static String[] getDemoArray() {
        return new String[]{"Tom", "Jerry", "Sinba", "Woodi"};
    }
    
    protected static List<String> getDemoList() {
        return Arrays.asList(getDemoArray());
    }
    
    protected static String[] getArrayFromFile() throws IOException {
        Path path = Paths.get("hibernate.log");
        System.err.println(path.toFile().getAbsolutePath());
        byte[] readAllBytes = Files.readAllBytes(path);
        String contents = new String(readAllBytes, StandardCharsets.UTF_8);
        return contents.split("[\\P{L}]+");
    }
    
    protected static String[] getArrayFromFile(String filePath) throws IOException {
        Path path = Paths.get(filePath);
        System.err.println(path.toFile().getAbsolutePath());
        byte[] readAllBytes = Files.readAllBytes(path);
        String contents = new String(readAllBytes, StandardCharsets.UTF_8);
        return contents.split("[\\P{L}]+");
    }
    
    protected static List<String> getListFromFile() throws IOException {
        return Arrays.asList(getArrayFromFile());
    }
    
    protected static List<String> getListFromFile(String filePath) throws IOException {
        return Arrays.asList(getArrayFromFile(filePath));
    }
}
